package com.wufun.overseas.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;

import com.wufun.overseas.models.bean.CommonRequestBean;
import com.wufun.overseas.models.bean.CommonRequestMessage;
import com.wufun.overseas.models.bean.RequestHandShankAdListArgs;

/**
 * Created by pengsk on 2014/12/31.
 */
public class RequestBeanUtil {

    private static String          end;
    private static String          imei;
    private static String          channel_num;
    private static RequestBeanUtil ourInstance;
    private String versionAndVersionName = "1_1.0";
    private String ad;

    //add by 唐炳良
    private static String mobile_phone_model;
    private static String mac;
    private static String ip_address;

    public static RequestBeanUtil getInstance(Context context) {

        if (ourInstance == null) {
            ourInstance = new RequestBeanUtil(context);
        }
        return ourInstance;
    }

    public static String getImei() {
        return imei;
    }

    public static void setImei(String imei) {
        RequestBeanUtil.imei = imei;
    }

    public static String getMobile_phone_model() {
        return mobile_phone_model;
    }

    public static void setMobile_phone_model(String mobile_phone_model) {
        RequestBeanUtil.mobile_phone_model = mobile_phone_model;
    }

    private RequestBeanUtil(Context context) {
//        TelephonyManager tm = (TelephonyManager) context
//                .getSystemService(Context.TELEPHONY_SERVICE);
//        imei = tm.getDeviceId();
//        ad = com.papa.sim.statistic.MetaUtils.getAd(context);
        imei = SystemInfoUtils.getInstance(context).getDeviceId();
        if (null == imei || imei.equals("")) {
            imei = SystemInfoUtils.getInstance(context).getMacAddress().replaceAll(":", "");
        }
        String md5String = imei + "gzRN53VWRF9BYUXo" + "mg2014";
        end = MD5Util.stringToMD5(md5String);
        Log.v("infoo", "imei   shi " + imei + "  md5String=  " + md5String + "   end=" + end);
//        channel_num = com.papa.sim.statistic.MetaUtils.getAd(context);
        //add by 唐炳良
        mobile_phone_model = android.os.Build.MODEL;
        mac = GetPhoneAddressUtil.getAdresseMAC(context);
        ip_address = GetPhoneAddressUtil.getNetIp();
        try {
            PackageInfo packageInfo = context.getPackageManager()
                    .getPackageInfo(context.getPackageName(), 0);
            int    versionCode = packageInfo.versionCode;
            String versionName = packageInfo.versionName;
            versionAndVersionName = versionCode + "_" + versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }

    public CommonRequestBean getHandShankAdList() {
        CommonRequestBean adListRequestBean = new CommonRequestBean(versionAndVersionName, imei, channel_num, end, new CommonRequestMessage(new RequestHandShankAdListArgs(1, 1, "test")));
        return adListRequestBean;
    }
}
